//
//  WHTdsSelectViewCell.m
//  WHEasyBizLink
//
//  Created by hyf on 2024/12/9.
//

#import "WHTdsSelectViewCell.h"
#import "UIView+Rounded.h"
#import "SDAutoLayout.h"
#import "WHTdsModel.h"

@interface WHTdsSelectViewCell ()

@property(nonatomic,strong)UIView*mbgView;

/** 平台名称  **/
@property (nonatomic, strong)UILabel*mTdsNameLabel;

/** 平台状态  **/
@property(nonatomic,weak)UISwitch *mTdsStatusSwitch;

/** 提示  **/
@property (nonatomic, strong)UILabel*mMsgLabel;
@end

@implementation WHTdsSelectViewCell

- (void)createUIControls{
    [super createUIControls];
    
    self.backgroundColor = tableBgLightgrayColor;
    
    self.mbgView =[[UIView alloc] init];
    self.mbgView.backgroundColor = [UIColor whiteColor];
    
    [self.contentView addSubview:self.mbgView];
    [UIView setViewRoundedWithRad:10 byRoundingCorners:UIRectCornerAllCorners view:self.mbgView];
    
    /**  公司名称  **/
    UILabel *tdsNameLabel = [[UILabel alloc]init];
    tdsNameLabel.font = [UIFont systemFontOfSize:17*WidthScale>19?19:17*WidthScale];
    tdsNameLabel.textColor = RGBColor(80, 141, 201);
    tdsNameLabel.lineBreakMode = NSLineBreakByTruncatingTail;
    tdsNameLabel.numberOfLines = 2;
    [self.mbgView addSubview:tdsNameLabel];
    self.mTdsNameLabel = tdsNameLabel;
    
    /**  提示  **/
    UILabel *msgLabel = [[UILabel alloc]init];
    msgLabel.font = [UIFont systemFontOfSize:12];
    msgLabel.textColor = [UIColor redColor];
    msgLabel.text = @"没有代理服务器，请联系管理员。";
    msgLabel.lineBreakMode = NSLineBreakByTruncatingTail;
    msgLabel.numberOfLines = 1;
    msgLabel.hidden = YES;
    [self.mbgView addSubview:msgLabel];
    self.mMsgLabel = msgLabel;
    
    //状态按钮
    UISwitch *tdsStatusSwitch = [[UISwitch alloc]init];
    [tdsStatusSwitch addTarget:self action:@selector(tdsStatusSwitchAction:) forControlEvents:UIControlEventValueChanged];
    [self.mbgView addSubview:tdsStatusSwitch];
    self.mTdsStatusSwitch = tdsStatusSwitch;
}

- (void)setUpUIControlsLayout{
    [super setUpUIControlsLayout];
    _mbgView
    .sd_layout
    .topSpaceToView(self.contentView, 10)
    .bottomSpaceToView(self.contentView, 10)
    .leftSpaceToView(self.contentView, 20)
    .rightSpaceToView(self.contentView,20);
    
    /**  平台状态  **/
    _mTdsStatusSwitch
    .sd_layout
    .topSpaceToView(self.mbgView,25)
    .rightSpaceToView(self.mbgView,10)
    .widthIs(40)
    .heightIs(40);
    
    /**  平台名称  **/
    _mTdsNameLabel
    .sd_layout
    .topSpaceToView(self.mbgView,10)
    .leftSpaceToView(self.mbgView,10)
    .rightSpaceToView(self.mTdsStatusSwitch,10)
    .heightIs(55);
    
    /**  提示  **/
    _mMsgLabel
    .sd_layout
    .bottomSpaceToView(self.mbgView, 2)
    .leftSpaceToView(self.mbgView,10)
    .rightSpaceToView(self.mTdsStatusSwitch,10)
    .heightIs(25);
}

-(void)setModel:(WHTdsModel *)model{
    _model = model;
    self.mTdsNameLabel.text = model.name;
    
    if (model.proxys.count>0) {
        self.mTdsNameLabel.textColor = RGBColor(80, 141, 201);
        self.mMsgLabel.hidden = YES;
    } else {
        self.mTdsNameLabel.textColor = [UIColor lightGrayColor];
        self.mMsgLabel.hidden = NO;
    }
    
    if(model.isSel){
        self.mTdsStatusSwitch.on = YES;
    }else{
        self.mTdsStatusSwitch.on = NO;
    }
}


- (void)tdsStatusSwitchAction:(UISwitch*)switchButton{
    if(self.model.proxys.count>0){
        if(self.clickBtnBlock)
        {
            self.clickBtnBlock(self.model);
        }
    }else{
        self.mTdsStatusSwitch.on = NO;
    }
}

@end
